package drds.binlog.common.position;

import drds.binlog.common.Authors;
import drds.common.Author;
import lombok.Getter;
import lombok.Setter;

/**
 * 数据库对象的唯一标示
 */
@Author(name = Authors.LI_YANG)
public class EntryPosition extends TimePosition
{

    @Setter
    @Getter
    private Long serverId = null;              // 记录一下位点对应的serverId
    @Setter
    @Getter
    private String journalName;
    @Setter
    @Getter
    private Long position;
    //
    @Setter
    @Getter
    private boolean included = false;

    @Setter
    @Getter
    private String gtid = null;

    public EntryPosition()
    {
        super(null);
    }

    public EntryPosition(Long timestamp)
    {
        this(null, null, timestamp);
    }

    public EntryPosition(String journalName, Long position)
    {
        this(journalName, position, null);
    }

    public EntryPosition(String journalName, Long position, //
                         Long timestamp)
    {
        super(timestamp);
        //
        this.journalName = journalName;
        this.position = position;
    }

    public EntryPosition(Long serverId,//
                         String journalName, Long position,//
                         Long timestamp)
    {
        this(journalName, position, timestamp);
        this.serverId = serverId;
    }


    public int compareTo(EntryPosition entryPosition)
    {
        final int compareTo = journalName.compareTo(entryPosition.journalName);

        if (compareTo == 0)
        {
            return (int) (position - entryPosition.position);
        }
        return compareTo;
    }

}
